<template>
  <div class="container">
    <el-form :model='searchList' ref='searchList' size='normal'>
      <el-row :gutter='20'>
        <el-col :span='8' :offset='0'>
          <el-form-item label=''>
            <el-input v-model='searchList.orgCode' placeholder="单位code" clearable></el-input>
          </el-form-item>
        </el-col>
        <el-col :span='8' :offset='0'>
          <el-form-item label=''>
            <el-input v-model='searchList.departName' placeholder="单位名称" clearable></el-input>
          </el-form-item>
        </el-col>
        <el-col :span='8' :offset='0'>
          <div class='right'>
            <el-button type='primary' size='medium' @click='onAdd' :loading="loading">添加</el-button>
            <el-button type='primary' size='medium' @click='search' :loading="loading">查询</el-button>
          </div>
        </el-col>
      </el-row>
    </el-form>

    <el-table :data='tableData.records' border stripe :height='offsetHeight' v-loading='loading' ref='tableData'>
      <el-table-column type='index' label='序号' width='80' align='center'>
      </el-table-column>
      <el-table-column prop='orgCode' label='登录账号' align='center'>
      </el-table-column>
      <el-table-column prop='departName' label='单位名称' align='center'>
      </el-table-column>
      <el-table-column prop='createTime' label='创建时间' width='150' align='center'>
      </el-table-column>
      <el-table-column label='操作' width='200' align='center'>
        <template slot-scope="{row}">
          <el-button-group>
            <el-button type="primary" size="mini" @click="onEdit(row)">编辑</el-button>
          </el-button-group>
        </template>
      </el-table-column>
    </el-table>
    <div class='page'>
      <el-pagination @size-change='pageSizeChange' @current-change='pageNoChange' :page-sizes='[10, 50, 100, 200]'
        :page-size='10' layout='total, sizes, prev, pager, next' :total='tableData.total'>
      </el-pagination>
    </div>

    <!-- 账号信息 -->
    <el-dialog title="中标信息" :visible.sync="addShow" width="30%" @close="cancel" :destroy-on-close="true" append-to-body>
      <el-form :model="addList" ref="editList" size="normal">
        <el-form-item label="单位名称">
          <el-input v-model="addList.departName">
          </el-input>
        </el-form-item>
        <el-form-item label="统一信用代码">
          <el-input v-model="addList.code">
          </el-input>
        </el-form-item>
      </el-form>
      <div class="center">
        <el-button type="danger" size="default" @click="cancel">取消</el-button>
        <el-button type="primary" size="default" @click="add" :loading="saveLoading">保存</el-button>
      </div>
    </el-dialog>

    <!-- 账号信息 -->
    <el-dialog title="中标信息" :visible.sync="editShow" width="30%" @close="cancel" :destroy-on-close="true"
      append-to-body>
      <el-form :model="editList" ref="editList" size="normal">
        <el-form-item label="单位名称">
          <el-input v-model="editList.departName">
          </el-input>
        </el-form-item>
      </el-form>
      <div class="center">
        <el-button type="danger" size="default" @click="cancel">取消</el-button>
        <el-button type="primary" size="default" @click="save" :loading="saveLoading">保存</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  name: '',
  components: {},
  props: {},
  data () {
    return {
      offsetHeight: document.documentElement.clientHeight - 200,
      loading: false,
      saveLoading: false,
      searchList: {},
      tableData: [],
      pageNo: '1',
      pageSize: '10',
      addList: {},
      addShow: false,
      editList: {},
      editShow: false
    }
  },
  created () {
  },
  mounted () {
    this.init()
  },
  methods: {
    async init () {
      this.loading = true
      const res = await this.$http('yqBidPage', {
        requestType: 'get',
        pageNo: this.pageNo,
        pageSize: this.pageSize,
        ...this.searchList
      })
      this.tableData = res
      this.loading = false
    },
    search () {
      this.pageNo = '1'
      this.pageSize = '10'
      this.init()
    },
    onAdd () {
      this.addShow = true
    },
    async add () {
      this.saveLoading = true
      const res = await this.$http('yqBidAdd', {
        ...this.addList
      })
      this.$tips.success(res.message)
      this.saveLoading = false
      this.cancel()
      this.init()
    },
    onEdit (item) {
      this.editList = {
        id: item.id,
        departName: item.departName
      }
      this.editShow = true
    },
    async save () {
      this.saveLoading = true
      const res = await this.$http('yqBidEdit', {
        requestType: 'PUT',
        ...this.editList
      })
      this.$tips.success(res.message)
      this.saveLoading = false
      this.cancel()
      this.init()
    },
    cancel () {
      this.addList = {}
      this.addShow = false
      this.editList = {}
      this.editShow = false
      this.saveLoading = false
    },
    pageNoChange (pageNo) {
      this.pageNo = pageNo
      this.init()
    },
    pageSizeChange (pageSize) {
      this.pageSize = pageSize
      this.init()
    }
  },
  computed: {
  }
}
</script>
<style lang='scss' scoped>
</style>